#!/bin/bash
#
#

CASSANDRA_DIR=/usr/local/cassandra
CASSANDRA_HOST="$1"


# add java
sudo yum -y install java

# create cassandra user and group. create related directories
sudo /usr/sbin/adduser -m -U cassandra
sudo mkdir ${CASSANDRA_DIR}
cd ${CASSANDRA_DIR} 

sudo tar xvfz /tmp/apache-cassandra-1.0.7-bin.tar.gz

sudo cp /tmp/cassandra /etc/init.d/
sudo cp /tmp/bashrc.cassandra /home/cassandra/.bashrc
sudo cp /tmp/cassandra.yaml.${CASSANDRA_HOST} ${CASSANDRA_DIR}/apache-cassandra-1.0.7/conf/cassandra.yaml

sudo mkdir /var/lib/cassandra /var/log/cassandra
sudo chown cassandra:cassandra /var/lib/cassandra /var/log/cassandra /home/cassandra/.bashrc ${CASSANDRA_DIR}/apache-cassandra-1.0.7/conf/cassandra.yaml

# start Cassandra
sudo /etc/init.d/cassandra start

exit
